#!/bin/bash
# Author : Syuan-Rong Chen
# E-mail : calvin.atx@gmail.com
# Blog：   http://calvinit.blogspot.com
# Date : 20100812
#
# <description>
# Copyright (C) <year>  <name> <email>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
dfpath=$HOME/calvin
appath=$HOME/calvin/bhuser
druser=$HOME/calvin/bhuser/user.txt


. /usr/cbin/c/ckroot

clear

function ck_user {
	if [ ! -e $druser  ]; then
		[ ! -e $dfpath ]&& mkdir $dfpath
		[ ! -e $appath ]&& mkdir $appath
		touch $druser 
		echo "username:password" >> $druser 
		nano $druser 
	else
		nano $druser 
	fi
}

function outputMenu {

echo -e '\E[1;33m'"歡迎使用Calvin_BHUSER v1.100815"; tput sgr0
echo ""
echo -e '\E[1;32m'"本程式主要功能為批次建立/刪除使用者，根據user.txt中的使用者資料"
echo              "請先編輯user.txt才能確保程式功能完整"
echo 		  "user.txt內容的格式為 帳號:密碼"
echo		  "user.txt存在$HOME/calvin/bhuser 可手動修改/備份"; tput sgr0
echo ""
echo "[1] 編輯user.txt"
echo "[2] 批次建立使用者"
echo "[3] 批次刪除使用者"
echo "[4] 顯示所有使用者"
echo ""
echo "[5] 關於作者"
echo "[0] 結束程式"

echo ""
echo -ne "請選擇: "
read USERCHOICE
clear

case $USERCHOICE in
        "1") ck_user ;;
        "2") . /usr/cbin/d-bhuser/mk.sh ;;
	"3") . /usr/cbin/d-bhuser/rm.sh ;;
	"4")
		cat /etc/passwd |cut -d: -f1 |fmt -u
		echo ""
		;;
	"5") . /usr/cbin/c/0-ME ;;
	"0") exit 0;;
        *) echo "請輸入正確的選擇";;
esac
}

. /usr/cbin/c/domenu.sh

